<template>
  <el-form
    :model="formData"
    ref="formRef"
    :rules="formRefRules"
    label-width="120px"
  >
    <el-form-item
      label="用户名"
      prop="name"
    >
      <el-input v-model="formData.name" />
    </el-form-item>
    <el-form-item>
      <el-button
        type="primary"
        @click="submitForm"
      >
        提交
      </el-button>
      <el-button @click="resetForm">
        重置
      </el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'
const formRef = ref<FormInstance>()
const formOption = reactive({
  formData: {
    name: 'liutao'
  },
  formRefRules: {
    name: [
      { required: true, message: '请输入用户名', trigger: 'blur' }
    ]
  } as FormRules,
  submitForm () {
    formRef.value?.validate(isValid => {
      console.log(isValid)
    })
    console.log(formRef.value, '提交')
  },
  resetForm () {
    formRef.value?.resetFields()
    console.log('重置')
  }
})
const { formData, formRefRules, submitForm, resetForm } = toRefs(formOption)
</script>

<style scoped>

</style>
